package com.nondo.rdp.finance.endpoint.api.app;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.nondo.rdp.core.model.View;
import com.nondo.rdp.finance.common.PayConfig;
import com.nondo.rdp.finance.common.XXPayUtil;
import com.nondo.rdp.finance.model.PayChannel;

@RestController("apiAppPayment")
@RequestMapping("/api/app/payment")
public class PaymentEndpoint {

	private static Logger _log = LoggerFactory.getLogger(PaymentEndpoint.class);

	private static final String mchId = "10000000";

	@SuppressWarnings("unchecked")
	@RequestMapping("/channel/list")
	public View<List<PayChannel>> channelList() {
		View<List<PayChannel>> view = new View<List<PayChannel>>(20000, "获取成功");

		JSONObject paramMap = new JSONObject();
		paramMap.put("mchId", mchId);
		String result = XXPayUtil.call4Post(PayConfig.channelListUrl, paramMap.toJSONString());
		_log.info("返回数据：result={}", result);
		JSONObject resultObject = JSONObject.parseObject(result);
		JSONArray resultArray = resultObject.getJSONArray("result");
		List<PayChannel> payChannelList = JSONArray.toJavaObject(resultArray, List.class);
		view.setData(payChannelList);
		return view;
	}
}